﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class EnemyObject : SlotObject
{
    // Start is called before the first frame update
    protected new void Start()
    {
        slot.gridManager.Player.ListAdd(this);
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    protected virtual void OnDestroy()
    {
        slot.gridManager.DropTreasure(slot.GridPosition);
        int t = Random.Range(0, 2);
        if(t == 0)
            slot.gridManager.DropTreasure(slot.GridPosition);
        slot.gridManager.Player.AddScore(150);
    }

    public override bool Move(int dx, int dy, float duration = 0.3f) {
        base.Move(dx, dy, duration);
        if(slot.SlotState == Slot.State.player) {
            OnPlayerTouch(slot.gridManager.Player);
            return true;
        }
        slot.SlotState = Slot.State.enemy;
        return true;
    }

    public override bool OnPlayerTouch(Player player, int dx = 0, int dy = 0) {
        player.Hurt(1);
        Destroy(gameObject, 0.3f);
        return true;
    }

    public abstract bool MoveToPlayer();
}
